/*
 * GPIO5.h
 *
 *  Created on: Mar 22, 2021
 *      Author: xrj
 */

#ifndef INC_GPIO5_H_
#define INC_GPIO5_H_

#include "stm32f1xx_hal.h"

#define BITBAND(addr, bitnum) (0x42000000+((addr-0x40000000)*8+bitnum)*4)
#define MEM_ADDR(addr)  *((volatile unsigned long  *)(addr))
#define BIT_ADDR(addr, bitnum)   MEM_ADDR(BITBAND(addr, bitnum))

typedef enum  //Strong, negative, positive
{             //BSRR(1bit), CNF/MODE(4bit)
  GPIO_Stro_down = 0b00010,  //0b 0 00 10
  GPIO_Week_down = 0b01000,  //0b 0 10 00
  GPIO_Float     = 0b00100,  //0b 0 01 00
  GPIO_Week_up   = 0b11000,  //0b 1 10 00
  GPIO_Stro_up   = 0b10010,  //0b 1 00 10
}GPIO_State5;                          //MODE=10: 2MHz

#define IsUp_IMsk  0xffffffef
#define Week_Msk   0b01000
#define FloatMsk   0b00100
#define Stro_Msk   0b00011
#define CRLH_Msk   0b01111

#define IsUp_Sft = 4;  // right shift 4bit for get value

extern GPIO_State5 GPIO_S5[5];

void GPIO_Init5(GPIO_TypeDef* GPIOx, uint32_t PinX);
void GPIO_Set5(GPIO_TypeDef* GPIOx, uint32_t PinX, GPIO_State5 NewState);
void GPIO_SetCRLH(GPIO_TypeDef* GPIOx, uint32_t PinX, uint32_t crlh);

#endif /* INC_GPIO5_H_ */
